package com.um.jdy.app.user.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.app.user.entity.dto.MonthCardBuyParam;
import com.um.jdy.app.user.entity.dto.MonthCardUpgradeParam;
import com.um.jdy.app.user.manager.MonthCardManager;
import com.um.springboot.starter.annotation.ActionLogRequired;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 用户月卡
 *
 * @author rnejunwei
 * @date 2021/1/24
 */
@RestController
@RequestMapping("/api/v1/user/month_card")
@Validated
public class MonthCardController{

    @Autowired
    MonthCardManager monthCardManager;

    @SaCheckLogin
    @ApiOperation("查询网点月卡套餐列表")
    @GetMapping("{station_id}/package_list")
    public Response getPackageList(@ApiParam("网点ID") @PathVariable String station_id) {
        return Response.success(monthCardManager.getPackageList(station_id));
    }

    @SaCheckLogin
    @ApiOperation("月卡套餐购买")
    @PostMapping("buy")
    public Response packageBuy(@Valid @RequestBody MonthCardBuyParam param){
        return Response.success(monthCardManager.packageBuy(param));
    }

    @SaCheckLogin
    @ApiOperation("查询升级月卡套餐列表")
    @GetMapping("{package_id}/upgrade_package_list")
    public Response getUpgradePackageList(@ApiParam("当前套餐ID") @PathVariable String package_id) {
        return Response.success(monthCardManager.getUpgradePackageList(package_id));
    }

    @SaCheckLogin
    @ApiOperation("升级月卡套餐")
    @PostMapping("package_upgrade")
    public Response packageUpgrade(@Valid @RequestBody MonthCardUpgradeParam param){
        return Response.success(monthCardManager.packageUpgrade(param));
    }

    @ActionLogRequired
    @RequestMapping("wxpay/notify/{com_id}")
    public Response wxPayNotify(HttpServletRequest request, @PathVariable String com_id) {
        monthCardManager.wxPayNotify(request, com_id);
        return Response.success();
    }

}
